#include "choose.h"
#include<QMenuBar>
#include<QPainter>
#include<QDebug>
#include"mypushbutton.h"
#include<QTimer>
#include<QLabel>
#include<QSound>
Choose::Choose(QWidget *parent) : QMainWindow(parent)
{
    QSound * backSound = new QSound(":/res/TapButtonSound.wav",this);

    this->setFixedSize(320,588);
    this->setWindowIcon(QPixmap(":res/Coin0001.png"));

    QMenuBar * bar = menuBar();
    setMenuBar(bar);

    QMenu * startMenu = bar->addMenu("开始");
    QAction * quitAction = startMenu->addAction("退出");
    connect(quitAction,&QAction::triggered,[=](){
        this->close();
    });


    MypushButton *backBtn = new MypushButton(":/res/BackButton.png",":/res/BackButtonSelected.png");
    backBtn->setParent(this);
    backBtn->move(this->width()-backBtn->width(),this->height()-backBtn->height());

    connect(backBtn,&MypushButton::clicked,[=]()
    {
        qDebug()<<"点击了返回";
        backSound->play();
        QTimer::singleShot(500,this,[=](){
            emit this->Choosebackbutton();
        });
    });


    for(int i = 0;i<20;i++)
    {
        MypushButton * menuBtn = new MypushButton(":/res/LevelIcon.png");
        connect(menuBtn,&MypushButton::clicked,[=](){
            qDebug()<<QString("这是第 %1 关").arg(i+1);
            this->hide();
            player = new play(i+1);
            player->show();
            connect(player,&play::Choosebackbutton,[=](){
                this->show();
                delete player;
                player = NULL;
            });

        });

        menuBtn->setParent(this);
        menuBtn->move(25+i%4 *70,130+i/4*70);
        QLabel *label = new QLabel;
        label->setParent(menuBtn);
        label->setFixedSize(menuBtn->width(),menuBtn->height());
        label->setText(QString::number(i+1));
        label->setAlignment(Qt::AlignCenter | Qt::AlignVCenter);
        //label->move(25+i%4 *70,130+i/4*70);
    }


}


void Choose::paintEvent(QPaintEvent *)
{
    QPainter painter(this);
    QPixmap pix;
    pix.load(":/res/OtherSceneBg.png");
    painter.drawPixmap(0,0,this->width(),this->height(),pix);
    pix.load(":/res/Title.png");
    painter.drawPixmap( (this->width() - pix.width())*0.5,30,pix.width(),pix.height(),pix);
}
